package com.shz.utils;

import com.shz.dto.UserDTO;
import com.shz.pojo.User;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.ArrayList;
import java.util.List;

public class UserUtil {

    public static User getCurrentUser() {
        User user = (User) SecurityContextHolder.getContext ().getAuthentication ().getPrincipal();
        return user;
    }
    public static UserDTO toUserDTO(User user){
        UserDTO userDTO=new UserDTO();
        userDTO.setUsername(user.getUsername());

        return userDTO;
    }
    public static List<UserDTO> toUserDTOs(List<User> Users){
        List<UserDTO> res=new ArrayList<>();
        for (User user : Users) {
            UserDTO userDTO=new UserDTO();
            userDTO.setUsername(user.getUsername());

            res.add(userDTO);
        }
        return res;
    }
}
